package com.example;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

@WebServlet("/getsession")
public class GetSession extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      
        HttpSession session = req.getSession();
        
        try {
            int i = (int)session.getAttribute("number");
            resp.getWriter().write("服务器读取session成功, 获得对象number为:" + i);
        } catch (Exception e) {
            resp.getWriter().write("服务器读取session成功, 但未找到指定Attribute");
        }


    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

